package drawingBoard.myPanel;

import drawingBoard.ImageFrame;
import drawingBoard.action.ImageAction;

import javax.swing.*;
import java.awt.*;
import static drawingBoard.tool.Tool.*;

/**
 * 抽象面板 MyPanel
 * 工具面板 ToolPanel
 */
public class ToolPanel extends MyPanel{
    private JPanel toolPanel;  //目标返回值
    private JToolBar toolBar;

    @Override
    public void createPanel() {
        toolPanel = new JPanel();

        toolBar = new JToolBar("工具");  //创建工具栏
        toolBar.setOrientation(SwingConstants.VERTICAL);
        toolBar.setMargin(new Insets(2, 2, 2, 2));
        toolBar.setLayout(new GridLayout(6, 2, 2, 2));  //绘图工具分6行2列
    }

    @Override
    public void createAllButton(ImageFrame imageFrame){  //在工具栏上显示全部绘图工具按钮
        String[] tools = { PENCIL_TOOL, BRUSH_TOOL, COLORPICKED_TOOL, ATOMIZER_TOOL, ERASER_TOOL, LINE_TOOL, POLYGON_TOOL, RECT_TOOL,
                ROUND_TOOL, ROUNDRECT_TOOL,TEXT_TOOL, NEW_TOOL };
        for (int i = 0; i < tools.length; i++) {  //添加工具
            //ImageAction action = new ImageAction(new ImageIcon("img/" + toolarr[i] + ".jpg"), toolarr[i], imageFrame);  //eclipse
            ImageAction action = new ImageAction(new ImageIcon("src/main/resources/img/" + tools[i] + ".jpg"), tools[i], imageFrame);  //IDEA-Maven
            JButton button = new JButton(action);  //构造方法的参数使用Action类型
            toolBar.add(button);
        }
        toolPanel.add(toolBar);
    }

    @Override
    public JPanel getPanel(){  //获取Panel
        return toolPanel;
    }
}
